@extends('agent.mainlayout')
@section('title')
    <div class="title"><span>代理成员管理></span></div>

@endsection
<style>
    .one .tab1 {

    }

    .one .tab1 p {
        display: inline-block !important;
    }

</style>
@section('content')
    <!-- start 代理成员管理-->

    <div class="list2">
        <div id="daili" style="width: 90px;
    text-align: center;
    background: #36bc9b;
    padding: 8px 0;
    color: white;
    cursor: pointer;">新增代理
        </div>
        <hr/>
        <div class="top">
            <form id='search' action="{{url('center/agent')}}" method="get">
                <div class="top_left">
                    <span>代理级别</span>
                    <select name="lev" id="">
                        <option value="" selected>请选择级别</option>
                        @foreach($levinfo as $v)
                            <option value="{{$v['lev']}}">{{$v['lev_name']}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="top_right">
                    <input type="text" name="keywords" placeholder="姓名/手机号"/>
                    <input type="hidden" name="status" value="{{isset($_GET['status'])?$_GET['status']:''}}">
                    <span onclick="$('#search').submit()">搜索</span>
                </div>
            </form>
        </div>

        <div class="tab1">
            <p @if(empty($_GET['status']))class="active"@endif><a href="/center/agent?status=0">待审核</a></p>
            <p @if(isset($_GET['status'])&&$_GET['status']!=0)class="active"@endif><a
                        href="/center/agent?status=1">已审核</a></p>
        </div>
        <table id="kuxuan">
            <tr>
                <th>姓名</th>
                <th>联系方式</th>
                <th>级别</th>
                <th>区域</th>
                <th>加入时间</th>
                <th>操作</th>
            </tr>
            @if(!empty($res['data']))
                @foreach($res['data'] as $v)
                    <tr>
                        <td>{{$v['agent_name']}}</td>
                        <td>{{$v['mobile']}}</td>
                        @foreach($levinfo as $v2)
                            @if($v['lev']==$v2['lev'])
                                <td>{{$v2['lev_name']}}</td>
                            @endif
                        @endforeach
                        <td>{{$v['area']}}</td>
                        <td>{{$v['created_at']}}</td>
                        <td>
                            @if($v['status']==0)
                                <span style="color:green;cursor: pointer;" onclick="verify(1,{{$v['id']}})">通过</span>
                                <span style="color:red;cursor: pointer;" onclick="verify(2,{{$v['id']}})">不通过</span>
                                <a href="{{url('center/brand/agent/info')}}?id={{$v['id']}}">
                                    <span style="color:green;text-decoration: underline;">详情</span>
                                </a>
                            @endif
                            @if($v['status']==1)
                                <span style="color: green;">已通过</span>
                                <a href="{{url('center/brand/agent/info')}}?id={{$v['id']}}">
                                    <span style="color:green;text-decoration: underline;">详情</span>
                                </a>
                                <span class="red" style="cursor: pointer;color: red;text-decoration: underline;"
                                      onclick="del({{$v['id']}})">删除</span>
                            @endif
                            @if($v['status']==2)
                                <span class="red" style="color: red;">已驳回</span>
                                <span class="red" style="cursor: pointer;color: red;text-decoration: underline;"
                                      onclick="del({{$v['id']}})">删除</span>

                            @endif
                        </td>

                    </tr>
                @endforeach
            @else
                <tr>
                    <td colspan="7">暂无数据(﹀_﹀")......</td>
                </tr>
            @endif
        </table>
        <!-- start 新增代理-->
        <div id="fixed" style="display: none">
            <form action="{{urlAdmin('Index','postAddAgent')}}" method="post" id="form1">
                <div class="fixed_one" id="fixed_one" style="position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -200px;
            margin-top: -260px;
            width: 400px;
            height: 500px;
            background: white;
            box-sizing: border-box;
            padding: 20px 30px;
            font-size: 15px;">
                    <h3>新增代理</h3>
                    <div class="one">
                        <p>代理姓名</p>
                        <input type="text" name="agent_name"/>
                    </div>
                    <div class="one">
                        <p>微信号</p>
                        <input type="text" name="wx"/>
                    </div>
                    <div class="one">
                        <p>手机号</p>
                        <input type="text" name="mobile"/>
                    </div>
                    <div class="one">
                        <p>密码</p>
                        <input type="password" name="password"/>
                    </div>
                    <div class="one">
                        <p>确认密码</p>
                        <input type="password" name="cpassword"/>
                    </div>
                    <div class="one">
                        <p>级别</p>
                        <select name="lev" id="">
                            <option value="" selected>请选择级别</option>
                            @foreach($levinfo as $v)
                                <option value="{{$v['lev']}}">{{$v['lev_name']}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="one">
                        <p>区域</p>
                        <input type="text" name="area"/>
                    </div>

                    <div class="footer">
                        <p id="queding1">确定</p>
                        <p id="quxiao1">取消</p>
                    </div>
                </div>
            </form>
        </div>
        <!-- end 新增代理-->
        <div class="del">
            <div class="bot" id="fenye">
                @if($res['last_page']>1)
                    @if($res['prev_page_url'])
                        <p class="prev"><a href="{{$res['prev_page_url']}}&status={{$_GET['status']}}">上一页</a></p>
                    @endif
                    <ul>
                        @foreach($res['pageNoList'] as $v)
                            <li @if($res['current_page'] ==  $v )class="active_list" @endif ><a
                                        href="/center/agent?page={{$v}}&status={{isset($_GET['status'])?$_GET['status']:0}}">{{$v}}</a>
                            </li>
                        @endforeach
                    </ul>
                    @if($res['next_page_url'])
                        <p class="next"><a
                                    href="{{$res['next_page_url']}}&status={{isset($_GET['status'])?$_GET['status']:0}}">下一页</a>
                        </p>
                    @endif
                @endif
            </div>
        </div>
    </div>
@endsection
<script>
    //单个删除
    function del(id) {

        layer.confirm('确定要删除该项吗?', {btn: ['确定', '取消']}, function () {
            layer.closeAll();
            //alert(id);
            $.ajax({
                type: 'get',
                url: "{{urlAdmin('Index','getAgentDel')}}",
                data: {id: id},
                dataType: 'json',
                success: function (res) {


                    if (res['status'] == 1) {

                        layer.msg(res.msg, {icon: 6});
                        setTimeout("location.reload()", 1500);

                    } else {

                        layer.msg(res.msg, {icon: 5});

                    }

                }

            });

        }, function () {

            layer.msg('你取消了!');

        });
    }


    //审核代理
    function verify(m, id) {
        layer.confirm('您确定该操作吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "post",
                url: "/center/agent/verify",
                data: {id: id, status: m},
                dataType: "json",
                success: function (res) {
                    if (res['status'] == 1) {
                        layer.msg('操作成功', {icon: 6});
                        setTimeout("location.reload()", 2000);
//                        $('#tr_'+id).hide();
                    } else {
                        layer.msg('操作失败', {icon: 5});
                        setTimeout("location.reload()", 2000);
                    }
                }
            })

        });
    }
    window.onload = function () {

        $('#queding1').click(function () {


            $.ajax({
                type: 'post',
                url: "{{urlAdmin('Index','postAddAgent')}}",
                data: $('form').serializeArray(),
                dataType: 'json',
                success: function (res) {
                    //关闭所有层
                    layer.closeAll();
                    $('#fixed,#fixed_one').css('display', 'none');
                    if (res.status == 1) {
                        layer.msg(res.msg, {icon: 6});
                        setTimeout("location.reload()", 2000);
                        //setTimeout("location.href='index.php?c=user&a=login'",2000);
                    } else {
                        layer.msg(res.msg, {icon: 5});

                    }
                }
            });


        });


        $('#quxiao1').click(function () {


            $('#fixed,#fixed_one').css('display', 'none');
            $('#fenye').css('display', 'block');

        });

        $('#daili').click(function () {


            $('#fixed,#fixed_one').css('display', 'block');
            $('#fenye').css('display', 'none');


        });


        $('.del a').click(function () {

            layer.load(2, {shade: false});

        });


        /******start三级联动******/

        {{--var url = "{{url('center/getaddress')}}";--}}
        {{--//console.log(data);--}}
        {{--$.ajax({--}}
        {{--type:"GET",--}}
        {{--url:url,--}}
        {{--dataType:"json",--}}
        {{--success:function(res){--}}
        {{--var num = "<option value=0 >请选择省份</option>";--}}
        {{--for(var i=0;i<res.length;i++){--}}

        {{--num+= "<option value="+ res[i]['area_id']  + ">" +  res[i]['area_name']  +"</option>";--}}
        {{--}--}}

        {{--$('.top_center').find('select').eq(0).html(num);--}}

        {{--}--}}
        {{--});--}}



        {{--$('.top_center').find('select').eq(0).change(function(){--}}
        {{--//清空下级--}}
        {{--//$('.top_center').find('select').eq(1).html('');--}}

        {{--var pid =  $(this).val();--}}


        {{--var url = "{{url('center/getaddress')}}?pid="+pid;--}}
        {{--//console.log(data);--}}
        {{--$.ajax({--}}
        {{--type:"GET",--}}
        {{--url:url,--}}
        {{--dataType:"json",--}}
        {{--success:function(res){--}}
        {{--var num = '';--}}
        {{--for(var i=0;i<res.length;i++){--}}

        {{--num+= "<option value="+ res[i]['area_id']  + ">" +  res[i]['area_name']  +"</option>";--}}
        {{--}--}}

        {{--$('.top_center').find('select').eq(1).html(num);--}}

        {{--}--}}
        {{--});--}}



        {{--});--}}

        {{--$('.top_center').find('select').eq(1).change(function(){--}}

        {{--//清空下级--}}
        {{--//$('.top_center').find('select').eq(2).html('');--}}

        {{--var pid =  $(this).val();--}}


        {{--var url = "{{url('center/getaddress')}}?pid="+pid;--}}
        {{--//console.log(data);--}}
        {{--$.ajax({--}}
        {{--type:"GET",--}}
        {{--url:url,--}}
        {{--dataType:"json",--}}
        {{--success:function(res){--}}
        {{--var num = '';--}}
        {{--for(var i=0;i<res.length;i++){--}}

        {{--num+= "<option value="+ res[i]['area_id']  + ">" +  res[i]['area_name']  +"</option>";--}}
        {{--}--}}

        {{--$('.top_center').find('select').eq(2).html(num);--}}

        {{--}--}}
        {{--});--}}

        {{--});--}}

        {{--$('.top_center').find('select').eq(1).click(function(){--}}

        {{--//清空下级--}}
        {{--//$('.top_center').find('select').eq(2).html('');--}}

        {{--var pid =  $(this).val();--}}


        {{--var url = "{{url('center/getaddress')}}?pid="+pid;--}}
        {{--//console.log(data);--}}
        {{--$.ajax({--}}
        {{--type:"GET",--}}
        {{--url:url,--}}
        {{--dataType:"json",--}}
        {{--success:function(res){--}}
        {{--var num = '';--}}
        {{--for(var i=0;i<res.length;i++){--}}

        {{--num+= "<option value="+ res[i]['area_id']  + ">" +  res[i]['area_name']  +"</option>";--}}
        {{--}--}}

        {{--$('.top_center').find('select').eq(2).html(num);--}}

        {{--}--}}
        {{--});--}}

        {{--});--}}



        /******end三级联动******/


        /****酷炫效果*****/
        var oTable = document.getElementById('kuxuan');
        var aLi = oTable.getElementsByTagName('tr');
        //var arr = ['red','blue','grey'];
        var str = '';
        for (var i = 1; i < aLi.length; i++) {

            //aLi[i].style.background = arr[i%3];

            aLi[i].onmouseover = function () {
                str = this.style.background;      //将原来的颜色保存起来
                this.style.background = '#2bdacf';
            }

            aLi[i].onmouseout = function () {
                this.style.background = str;
            }

        }
        /****酷炫效果******/


        var oSearch = document.getElementById('search');
        var oSpan = oSearch.getElementsByTagName('span')[2];

        oSpan.onclick = function () {

            oSearch.submit();

        }

    }

</script>
